æòÅⁿâoâiü[

JavaScript Reference


    Properties

      connected

      Boolean

      Contains true if the connection is still active. Read only.

      eof

      Boolean

      This property has the value true if the receive buffer is empty. Read only.

      error

      String

      Contains a message describing the last error. Setting this value clears any error message.

      host

      String

      Contains the name of the remote computer when a connection is established. If the connection is shut down or does not exists, the property contains the empty string. Read only.

      timeout

      Number

      The timeout in seconds to be applied to read or write operations. Defaults to 10 (ten seconds).

    Methods

      [new] Socket ();

      Creates a new Socket object.

    Returns

      Object.

      close();

      Terminates the open connection. The return value is true if the connection was closed, false on I/O errors. Deleting the connection has the same effect. Remember, however, that JavaScript garbage collects the object at some null time, so the connection may stay open longer than you want to if you do not close it explicitly.

    Returns

      Boolean

      listen (Number port [, String encoding]);

      Instructs the object to start listening for an incoming connection. The port argument is the TCP/IP port number where the object should listen on; typical values are 80 for a Web server, 23 for a Telnet server and so on. The encoding parameter is optional. The call to listen() is mutually exclusive to a call to open(). The result is true if the connection object successfully started listening, false otherwise.

    Parameters

      port

      Number

      The port number to listen on. Valid port numbers are 1 to 65535.

      encoding

      String

      The encoding to be used for the connection. Typical values are "ASCII", "binary", or "UTF-8". This parameter defaults to ASCII.

    Returns

      Boolean

      open (String computer [, String encoding]);

      Open the connection for subsequent read/write operations. The computer name is the name or IP address, followed by a colon and the port number to connect to. The port number is mandatory. Valid computer names are e.g. "www.adobe.com:80" or "192.150.14.12:80". The encoding parameter is optional; currently, it can be one of "ASCII", "binary" or "UTF-8". The call to open() is mutually exclusive to a call to listen().

    Parameters

      host

      String

      The name or IP address of the remote computer, followed by a colon and the port number to connect to. The port number is mandatory. Valid computer names are e.g. "www.adobe.com:80" or "192.150.14.12:80".

      encoding

      String

      The encoding to be used for the connection. Typical values are "ASCII", "binary", or "UTF-8". This parameter defaults to ASCII.

    Returns

      Boolean

      poll();

      Check a listening object for a new incoming connection. If a connection request was detected, the method returns a new Socket object that wraps the new connection. Use this connection object to communicate with the remote computer. After use, close the connection and delete the JavaScript object. If no new connection request was detected, the method returns null.

    Returns

      a new Socket object or null.

      read ([Number count]);

      Read up to the given number of characters from the connection. Returns a string that contains up to the number of characters that were supposed to be read. If no count is supplied, the connection attempts to read as many characters it can get until the remote server closes the connection or a timeout occurs.

    Parameters

      count

      Number

      The number of characters to read. If no count is supplied, the connection attempts to read as many characters it can get until the remote server closes the connection or a timeout occurs.

    Returns

      String

      readln();

      Read one line of text up to the next line feed. Line feeds are recognized as CR, LF, CRLF or LFCR pairs.

    Returns

      String

      write (String text, ╔);

      Write the given string to the connection. The parameters of this function are concatenated to a single string. Returns true on success.

    Parameters

      text

      String

      All arguments are concatenated to form the string to be written.

    Returns

      Boolean

      writeln (String text, ╔);

      Write the given string to the connection and append a Line Feed character. The parameters of this function are concatenated to a single string. Returns true on success.

    Parameters

      text

      String

      All arguments are concatenated to form the string to be written.

    Returns

      Boolean